%{
	#include "ts.h" 
	#include "y.tab.h"

	long yyval;
	int tok;
	token *ts;
	tabla T;
	tbloque TB;
	bloque *bq;

  
%}

OGGS		OggS
BYTE0		\x00
BYTE1		\x01
BYTE2		\x02
BYTE3		\x03
BYTE4		\x04
BYTE5		\x05
BYTE6		\x06
BYTE7		\x07
BYTE8		\x08
BYTE9		\x09
BYTE10		\x0a
BYTE11		\x0b
BYTE12		\x0c
BYTE13		\x0d
BYTE14		\x0e
BYTE15		\x0f
BYTE16		\x10
BYTE17		\x11
BYTE18		\x12
BYTE19		\x13
BYTE20		\x14
BYTE21		\x15
BYTE22		\x16
BYTE23		\x17
BYTE24		\x18
BYTE25		\x19
BYTE26		\x1a
BYTE27		\x1b
BYTE28		\x1c
BYTE29		\x1d
BYTE30		\x1e
BYTE31		\x1f
BYTE32		\x20
BYTE33		\x21
BYTE34		\x22
BYTE35		\x23
BYTE36		\x24
BYTE37		\x25
BYTE38		\x26
BYTE39		\x27
BYTE40		\x28
BYTE41		\x29
BYTE42		\x2a
BYTE43		\x2b
BYTE44		\x2c
BYTE45		\x2d
BYTE46		\x2e
BYTE47		\x2f
BYTE48		\x30
BYTE49		\x31
BYTE50		\x32
BYTE51		\x33
BYTE52		\x34
BYTE53		\x35
BYTE54		\x36
BYTE55		\x37
BYTE56		\x38
BYTE57		\x39
BYTE58		\x3a
BYTE59		\x3b
BYTE60		\x3c
BYTE61		\x3d
BYTE62		\x3e
BYTE63		\x3f
BYTE64		\x40
BYTE65		\x41
BYTE66		\x42
BYTE67		\x43
BYTE68		\x44
BYTE69		\x45
BYTE70		\x46
BYTE71		\x47
BYTE72		\x48
BYTE73		\x49
BYTE74		\x4a
BYTE75		\x4b
BYTE76		\x4c
BYTE77		\x4d
BYTE78		\x4e
BYTE79		\x4f
BYTE80		\x50
BYTE81		\x51
BYTE82		\x52
BYTE83		\x53
BYTE84		\x54
BYTE85		\x55
BYTE86		\x56
BYTE87		\x57
BYTE88		\x58
BYTE89		\x59
BYTE90		\x5a
BYTE91		\x5b
BYTE92		\x5c
BYTE93		\x5d
BYTE94		\x5e
BYTE95		\x5f
BYTE96		\x60
BYTE97		\x61
BYTE98		\x62
BYTE99		\x63
BYTE100		\x64
BYTE101		\x65
BYTE102		\x66
BYTE103		\x67
BYTE104		\x68
BYTE105		\x69
BYTE106		\x6a
BYTE107		\x6b
BYTE108		\x6c
BYTE109		\x6d
BYTE110		\x6e
BYTE111		\x6f
BYTE112		\x70
BYTE113		\x71
BYTE114		\x72
BYTE115		\x73
BYTE116		\x74
BYTE117		\x75
BYTE118		\x76
BYTE119		\x77
BYTE120		\x78
BYTE121		\x79
BYTE122		\x7a
BYTE123		\x7b
BYTE124		\x7c
BYTE125		\x7d
BYTE126		\x7e
BYTE127		\x7f
BYTE128		\x80
BYTE129		\x81
BYTE130		\x82
BYTE131		\x83
BYTE132		\x84
BYTE133		\x85
BYTE134		\x86
BYTE135		\x87
BYTE136		\x88
BYTE137		\x89
BYTE138		\x8a
BYTE139		\x8b
BYTE140		\x8c
BYTE141		\x8d
BYTE142		\x8e
BYTE143		\x8f
BYTE144		\x90
BYTE145		\x91
BYTE146		\x92
BYTE147		\x93
BYTE148		\x94
BYTE149		\x95
BYTE150		\x96
BYTE151		\x97
BYTE152		\x98
BYTE153		\x99
BYTE154		\x9a
BYTE155		\x9b
BYTE156		\x9c
BYTE157		\x9d
BYTE158		\x9e
BYTE159		\x9f
BYTE160		\xa0
BYTE161		\xa1
BYTE162		\xa2
BYTE163		\xa3
BYTE164		\xa4
BYTE165		\xa5
BYTE166		\xa6
BYTE167		\xa7
BYTE168		\xa8
BYTE169		\xa9
BYTE170		\xaa
BYTE171		\xab
BYTE172		\xac
BYTE173		\xad
BYTE174		\xae
BYTE175		\xaf
BYTE176		\xb0
BYTE177		\xb1
BYTE178		\xb2
BYTE179		\xb3
BYTE180		\xb4
BYTE181		\xb5
BYTE182		\xb6
BYTE183		\xb7
BYTE184		\xb8
BYTE185		\xb9
BYTE186		\xba
BYTE187		\xbb
BYTE188		\xbc
BYTE189		\xbd
BYTE190		\xbe
BYTE191		\xbf
BYTE192		\xc0
BYTE193		\xc1
BYTE194		\xc2
BYTE195		\xc3
BYTE196		\xc4
BYTE197		\xc5
BYTE198		\xc6
BYTE199		\xc7
BYTE200		\xc8
BYTE201		\xc9
BYTE202		\xca
BYTE203		\xcb
BYTE204		\xcc
BYTE205		\xcd
BYTE206		\xce
BYTE207		\xcf
BYTE208		\xd0
BYTE209		\xd1
BYTE210		\xd2
BYTE211		\xd3
BYTE212		\xd4
BYTE213		\xd5
BYTE214		\xd6
BYTE215		\xd7
BYTE216		\xd8
BYTE217		\xd9
BYTE218		\xda
BYTE219		\xdb
BYTE220		\xdc
BYTE221		\xdd
BYTE222		\xde
BYTE223		\xdf
BYTE224		\xe0
BYTE225		\xe1
BYTE226		\xe2
BYTE227		\xe3
BYTE228		\xe4
BYTE229		\xe5
BYTE230		\xe6
BYTE231		\xe7
BYTE232		\xe8
BYTE233		\xe9
BYTE234		\xea
BYTE235		\xeb
BYTE236		\xec
BYTE237		\xed
BYTE238		\xee
BYTE239		\xef
BYTE240		\xf0
BYTE241		\xf1
BYTE242		\xf2
BYTE243		\xf3
BYTE244		\xf4
BYTE245		\xf5
BYTE246		\xf6
BYTE247		\xf7
BYTE248		\xf8
BYTE249		\xf9
BYTE250		\xfa
BYTE251		\xfb
BYTE252		\xfc
BYTE253		\xfd
BYTE254		\xfe
BYTE255		\xff

%%

{OGGS}   		{yyval=-1; return HEADS;}

{BYTE0}			{yyval=0; return ONEB;}
{BYTE1}			{yyval=1; return ONEB;}
{BYTE2}			{yyval=2; return ONEB;}
{BYTE3}			{yyval=3; return ONEB;}
{BYTE4}			{yyval=4; return ONEB;}
{BYTE5}			{yyval=5; return ONEB;}
{BYTE6}			{yyval=6; return ONEB;}
{BYTE7}			{yyval=7; return ONEB;}
{BYTE8}			{yyval=8; return ONEB;}
{BYTE9}			{yyval=9; return ONEB;}
{BYTE10}		{yyval=10; return ONEB;}
{BYTE11}		{yyval=11; return ONEB;}
{BYTE12}		{yyval=12; return ONEB;}
{BYTE13}		{yyval=13; return ONEB;}
{BYTE14}		{yyval=14; return ONEB;}
{BYTE15}		{yyval=15; return ONEB;}
{BYTE16}		{yyval=16; return ONEB;}
{BYTE17}		{yyval=17; return ONEB;}
{BYTE18}		{yyval=18; return ONEB;}
{BYTE19}		{yyval=19; return ONEB;}
{BYTE20}		{yyval=20; return ONEB;}
{BYTE21}		{yyval=21; return ONEB;}
{BYTE22}		{yyval=22; return ONEB;}
{BYTE23}		{yyval=23; return ONEB;}
{BYTE24}		{yyval=24; return ONEB;}
{BYTE25}		{yyval=25; return ONEB;}
{BYTE26}		{yyval=26; return ONEB;}
{BYTE27}		{yyval=27; return ONEB;}
{BYTE28}		{yyval=28; return ONEB;}
{BYTE29}		{yyval=29; return ONEB;}
{BYTE30}		{yyval=30; return ONEB;}
{BYTE31}		{yyval=31; return ONEB;}
{BYTE32}		{yyval=32; return ONEB;}
{BYTE33}		{yyval=33; return ONEB;}
{BYTE34}		{yyval=34; return ONEB;}
{BYTE35}		{yyval=35; return ONEB;}
{BYTE36}		{yyval=36; return ONEB;}
{BYTE37}		{yyval=37; return ONEB;}
{BYTE38}		{yyval=38; return ONEB;}
{BYTE39}		{yyval=39; return ONEB;}
{BYTE40}		{yyval=40; return ONEB;}
{BYTE41}		{yyval=41; return ONEB;}
{BYTE42}		{yyval=42; return ONEB;}
{BYTE43}		{yyval=43; return ONEB;}
{BYTE44}		{yyval=44; return ONEB;}
{BYTE45}		{yyval=45; return ONEB;}
{BYTE46}		{yyval=46; return ONEB;}
{BYTE47}		{yyval=47; return ONEB;}
{BYTE48}		{yyval=48; return ONEB;}
{BYTE49}		{yyval=49; return ONEB;}
{BYTE50}		{yyval=50; return ONEB;}
{BYTE51}		{yyval=51; return ONEB;}
{BYTE52}		{yyval=52; return ONEB;}
{BYTE53}		{yyval=53; return ONEB;}
{BYTE54}		{yyval=54; return ONEB;}
{BYTE55}		{yyval=55; return ONEB;}
{BYTE56}		{yyval=56; return ONEB;}
{BYTE57}		{yyval=57; return ONEB;}
{BYTE58}		{yyval=58; return ONEB;}
{BYTE59}		{yyval=59; return ONEB;}
{BYTE60}		{yyval=60; return ONEB;}
{BYTE61}		{yyval=61; return ONEB;}
{BYTE62}		{yyval=62; return ONEB;}
{BYTE63}		{yyval=63; return ONEB;}
{BYTE64}		{yyval=64; return ONEB;}
{BYTE65}		{yyval=65; return ONEB;}
{BYTE66}		{yyval=66; return ONEB;}
{BYTE67}		{yyval=67; return ONEB;}
{BYTE68}		{yyval=68; return ONEB;}
{BYTE69}		{yyval=69; return ONEB;}
{BYTE70}		{yyval=70; return ONEB;}
{BYTE71}		{yyval=71; return ONEB;}
{BYTE72}		{yyval=72; return ONEB;}
{BYTE73}		{yyval=73; return ONEB;}
{BYTE74}		{yyval=74; return ONEB;}
{BYTE75}		{yyval=75; return ONEB;}
{BYTE76}		{yyval=76; return ONEB;}
{BYTE77}		{yyval=77; return ONEB;}
{BYTE78}		{yyval=78; return ONEB;}
{BYTE79}		{yyval=79; return ONEB;}
{BYTE80}		{yyval=80; return ONEB;}
{BYTE81}		{yyval=81; return ONEB;}
{BYTE82}		{yyval=82; return ONEB;}
{BYTE83}		{yyval=83; return ONEB;}
{BYTE84}		{yyval=84; return ONEB;}
{BYTE85}		{yyval=85; return ONEB;}
{BYTE86}		{yyval=86; return ONEB;}
{BYTE87}		{yyval=87; return ONEB;}
{BYTE88}		{yyval=88; return ONEB;}
{BYTE89}		{yyval=89; return ONEB;}
{BYTE90}		{yyval=90; return ONEB;}
{BYTE91}		{yyval=91; return ONEB;}
{BYTE92}		{yyval=92; return ONEB;}
{BYTE93}		{yyval=93; return ONEB;}
{BYTE94}		{yyval=94; return ONEB;}
{BYTE95}		{yyval=95; return ONEB;}
{BYTE96}		{yyval=96; return ONEB;}
{BYTE97}		{yyval=97; return ONEB;}
{BYTE98}		{yyval=98; return ONEB;}
{BYTE99}		{yyval=99; return ONEB;}
{BYTE100}		{yyval=100; return ONEB;}
{BYTE101}		{yyval=101; return ONEB;}
{BYTE102}		{yyval=102; return ONEB;}
{BYTE103}		{yyval=103; return ONEB;}
{BYTE104}		{yyval=104; return ONEB;}
{BYTE105}		{yyval=105; return ONEB;}
{BYTE106}		{yyval=106; return ONEB;}
{BYTE107}		{yyval=107; return ONEB;}
{BYTE108}		{yyval=108; return ONEB;}
{BYTE109}		{yyval=109; return ONEB;}
{BYTE110}		{yyval=110; return ONEB;}
{BYTE111}		{yyval=111; return ONEB;}
{BYTE112}		{yyval=112; return ONEB;}
{BYTE113}		{yyval=113; return ONEB;}
{BYTE114}		{yyval=114; return ONEB;}
{BYTE115}		{yyval=115; return ONEB;}
{BYTE116}		{yyval=116; return ONEB;}
{BYTE117}		{yyval=117; return ONEB;}
{BYTE118}		{yyval=118; return ONEB;}
{BYTE119}		{yyval=119; return ONEB;}
{BYTE120}		{yyval=120; return ONEB;}
{BYTE121}		{yyval=121; return ONEB;}
{BYTE122}		{yyval=122; return ONEB;}
{BYTE123}		{yyval=123; return ONEB;}
{BYTE124}		{yyval=124; return ONEB;}
{BYTE125}		{yyval=125; return ONEB;}
{BYTE126}		{yyval=126; return ONEB;}
{BYTE127}		{yyval=127; return ONEB;}
{BYTE128}		{yyval=128; return ONEB;}
{BYTE129}		{yyval=129; return ONEB;}
{BYTE130}		{yyval=130; return ONEB;}
{BYTE131}		{yyval=131; return ONEB;}
{BYTE132}		{yyval=132; return ONEB;}
{BYTE133}		{yyval=133; return ONEB;}
{BYTE134}		{yyval=134; return ONEB;}
{BYTE135}		{yyval=135; return ONEB;}
{BYTE136}		{yyval=136; return ONEB;}
{BYTE137}		{yyval=137; return ONEB;}
{BYTE138}		{yyval=138; return ONEB;}
{BYTE139}		{yyval=139; return ONEB;}
{BYTE140}		{yyval=140; return ONEB;}
{BYTE141}		{yyval=141; return ONEB;}
{BYTE142}		{yyval=142; return ONEB;}
{BYTE143}		{yyval=143; return ONEB;}
{BYTE144}		{yyval=144; return ONEB;}
{BYTE145}		{yyval=145; return ONEB;}
{BYTE146}		{yyval=146; return ONEB;}
{BYTE147}		{yyval=147; return ONEB;}
{BYTE148}		{yyval=148; return ONEB;}
{BYTE149}		{yyval=149; return ONEB;}
{BYTE150}		{yyval=150; return ONEB;}
{BYTE151}		{yyval=151; return ONEB;}
{BYTE152}		{yyval=152; return ONEB;}
{BYTE153}		{yyval=153; return ONEB;}
{BYTE154}		{yyval=154; return ONEB;}
{BYTE155}		{yyval=155; return ONEB;}
{BYTE156}		{yyval=156; return ONEB;}
{BYTE157}		{yyval=157; return ONEB;}
{BYTE158}		{yyval=158; return ONEB;}
{BYTE159}		{yyval=159; return ONEB;}
{BYTE160}		{yyval=160; return ONEB;}
{BYTE161}		{yyval=161; return ONEB;}
{BYTE162}		{yyval=162; return ONEB;}
{BYTE163}		{yyval=163; return ONEB;}
{BYTE164}		{yyval=164; return ONEB;}
{BYTE165}		{yyval=165; return ONEB;}
{BYTE166}		{yyval=166; return ONEB;}
{BYTE167}		{yyval=167; return ONEB;}
{BYTE168}		{yyval=168; return ONEB;}
{BYTE169}		{yyval=169; return ONEB;}
{BYTE170}		{yyval=170; return ONEB;}
{BYTE171}		{yyval=171; return ONEB;}
{BYTE172}		{yyval=172; return ONEB;}
{BYTE173}		{yyval=173; return ONEB;}
{BYTE174}		{yyval=174; return ONEB;}
{BYTE175}		{yyval=175; return ONEB;}
{BYTE176}		{yyval=176; return ONEB;}
{BYTE177}		{yyval=177; return ONEB;}
{BYTE178}		{yyval=178; return ONEB;}
{BYTE179}		{yyval=179; return ONEB;}
{BYTE180}		{yyval=180; return ONEB;}
{BYTE181}		{yyval=181; return ONEB;}
{BYTE182}		{yyval=182; return ONEB;}
{BYTE183}		{yyval=183; return ONEB;}
{BYTE184}		{yyval=184; return ONEB;}
{BYTE185}		{yyval=185; return ONEB;}
{BYTE186}		{yyval=186; return ONEB;}
{BYTE187}		{yyval=187; return ONEB;}
{BYTE188}		{yyval=188; return ONEB;}
{BYTE189}		{yyval=189; return ONEB;}
{BYTE190}		{yyval=190; return ONEB;}
{BYTE191}		{yyval=191; return ONEB;}
{BYTE192}		{yyval=192; return ONEB;}
{BYTE193}		{yyval=193; return ONEB;}
{BYTE194}		{yyval=194; return ONEB;}
{BYTE195}		{yyval=195; return ONEB;}
{BYTE196}		{yyval=196; return ONEB;}
{BYTE197}		{yyval=197; return ONEB;}
{BYTE198}		{yyval=198; return ONEB;}
{BYTE199}		{yyval=199; return ONEB;}
{BYTE200}		{yyval=200; return ONEB;}
{BYTE201}		{yyval=201; return ONEB;}
{BYTE202}		{yyval=202; return ONEB;}
{BYTE203}		{yyval=203; return ONEB;}
{BYTE204}		{yyval=204; return ONEB;}
{BYTE205}		{yyval=205; return ONEB;}
{BYTE206}		{yyval=206; return ONEB;}
{BYTE207}		{yyval=207; return ONEB;}
{BYTE208}		{yyval=208; return ONEB;}
{BYTE209}		{yyval=209; return ONEB;}
{BYTE210}		{yyval=210; return ONEB;}
{BYTE211}		{yyval=211; return ONEB;}
{BYTE212}		{yyval=212; return ONEB;}
{BYTE213}		{yyval=213; return ONEB;}
{BYTE214}		{yyval=214; return ONEB;}
{BYTE215}		{yyval=215; return ONEB;}
{BYTE216}		{yyval=216; return ONEB;}
{BYTE217}		{yyval=217; return ONEB;}
{BYTE218}		{yyval=218; return ONEB;}
{BYTE219}		{yyval=219; return ONEB;}
{BYTE220}		{yyval=220; return ONEB;}
{BYTE221}		{yyval=221; return ONEB;}
{BYTE222}		{yyval=222; return ONEB;}
{BYTE223}		{yyval=223; return ONEB;}
{BYTE224}		{yyval=224; return ONEB;}
{BYTE225}		{yyval=225; return ONEB;}
{BYTE226}		{yyval=226; return ONEB;}
{BYTE227}		{yyval=227; return ONEB;}
{BYTE228}		{yyval=228; return ONEB;}
{BYTE229}		{yyval=229; return ONEB;}
{BYTE230}		{yyval=230; return ONEB;}
{BYTE231}		{yyval=231; return ONEB;}
{BYTE232}		{yyval=232; return ONEB;}
{BYTE233}		{yyval=233; return ONEB;}
{BYTE234}		{yyval=234; return ONEB;}
{BYTE235}		{yyval=235; return ONEB;}
{BYTE236}		{yyval=236; return ONEB;}
{BYTE237}		{yyval=237; return ONEB;}
{BYTE238}		{yyval=238; return ONEB;}
{BYTE239}		{yyval=239; return ONEB;}
{BYTE240}		{yyval=240; return ONEB;}
{BYTE241}		{yyval=241; return ONEB;}
{BYTE242}		{yyval=242; return ONEB;}
{BYTE243}		{yyval=243; return ONEB;}
{BYTE244}		{yyval=244; return ONEB;}
{BYTE245}		{yyval=245; return ONEB;}
{BYTE246}		{yyval=246; return ONEB;}
{BYTE247}		{yyval=247; return ONEB;}
{BYTE248}		{yyval=248; return ONEB;}
{BYTE249}		{yyval=249; return ONEB;}
{BYTE250}		{yyval=250; return ONEB;}
{BYTE251}		{yyval=251; return ONEB;}
{BYTE252}		{yyval=252; return ONEB;}
{BYTE253}		{yyval=253; return ONEB;}
{BYTE254}		{yyval=254; return ONEB;}
{BYTE255}		{yyval=255; return ONEB;}

%%

void AddTabla(token *a){
	if(T.inicio!=NULL){
		T.fin->next=a;
		T.fin=a;
	}
	else{
		T.inicio=a;
		T.fin=a;
	}
}

unsigned BytADD (int n){
	unsigned count=0,expo=1;
	int i;
	
	for(i=0;i<n;i++){
		tok=_yylex();
		if(tok!=ONEB)
			return 0;
		count=count+yyval*expo;
		expo=expo*256;
	}return count;
}


int yylex(){
  
   int i,a;
   char *auxp;
int count=0;

int j;


   tok=_yylex();

//Value OggS
      if(tok==HEADS){
	 ts=(token *) malloc(sizeof(token));

//Value Version 0
	 tok=_yylex();
	 if(tok==ONEB && yyval==0){

//Value Heder Type 0,1,2,4 or 5
	    tok=_yylex();
	    if(tok==ONEB && (yyval>=0 && yyval<=5)&& yyval!=3 ){
		ts->type=yyval;

//Value Granule Position
		yyval=BytADD(8);
		if(tok==ONEB){
		    ts->granule=yyval;
//Value Stream Serial
		    yyval=BytADD(4);
		    if(tok==ONEB){
			ts->serial=yyval;

//Value Page Secuance
			yyval=BytADD(4);
			if(tok==ONEB){
			    ts->page=yyval;
//Value Checksum
			    yyval=BytADD(4);
			    if(tok==ONEB){

//Value Page Segments
				tok=_yylex();
				if(tok==ONEB){
				    ts->nsegment=yyval;
				    
				    ts->segments= (int *) calloc(yyval,sizeof(int));				   
				    for(i=0;i<ts->nsegment;i++){
					tok=_yylex();
					if(tok==ONEB){
						ts->segments[i]=yyval;
						count+=yyval;
					}
				    }
				   ts->datasize=count;
				   ts->data=(char*)malloc(count);
					count=0;
				    for(i=0;i<ts->nsegment;i++){
					for(j=0;j<ts->segments[i];j++){
						tok=_yylex();
						if(tok!=ONEB)
							return tok;
						ts->data[count+j]=yyval;
					}
					count+=ts->segments[i];
				    }
				    
				    AddTabla(ts);
				
				
				    switch(ts->type){
					case 0:
					    ts=NULL;
					    return HEAD0;
					case 1:
					    return HEAD1;
					case 2:
					    ts=NULL;
					    return HEAD2;
					case 4:
					    ts=NULL;
					    return HEAD4;
					case 5:
					    ts=NULL;
					    return HEAD4;
				      }
					printf("9");
				}
					printf("8");
			    }
					printf("7");
			}
					printf("6");
		    }
					printf("5");
		}
					printf("4");
	     }
					printf("3");
	  }
					printf("2");
	  free(ts);
      }
	if(yyval!=0){
					printf("1");
	printf("Error en Pagina: \"%X\"\n", (unsigned int)yyval);
	}
	return tok;
}


void MKV(){
	unsigned int serial1=0, i,count=0,k, count1,count2,j;
	float granulerate;
	ts=T.inicio;
	token *paux;
	do{
		ts=ts->next;
	}while(T.inicio->serial!=ts->serial);
	for(i=0; i<ts->nsegment;i++){
		if(strncmp(&(ts->data[count+58]),"theora",6)==0){
			for(j=1,k=15 ;k>= 12;j*=256, k--){//serial
				if(ts->data[count+k]<0)
					serial1+=(ts->data[count+k]+256)*j;
				else
					serial1+=ts->data[count+k]*j;
			}
			count1=0;
			for(j=1,k=27 ;k>= 20;j*=256, k--){//granulerate numerador
				if(ts->data[count+k]<0)
					count1+=(ts->data[count+k]+256)*j;
				else
					count1+=ts->data[count+k]*j;
			}
			count2=0;
			for(j=1,k=35 ;k>= 28;j*=256, k--){//granulerate denominador
				if(ts->data[count+k]<0)
					count2+=(ts->data[count+k]+256)*j;
				else
					count2+=ts->data[count+k]*j;
			}
			granulerate=count1/count2;
			break;
		}
		else
			count+=ts->segments[i];
	}

//TRADUCCION
	ts=T.inicio;
	do{
		if(ts->serial==serial1){
			while(ts->granule==-1){
				paux=ts->next;
				ts->granule=paux->granule;				
				ts->segments=(int *) realloc(ts->segments,ts->nsegment+paux->nsegment);
				for(i=0;i<paux->nsegment;i++)
					ts->segments[i+ts->nsegment]=paux->segments[i];
				ts->nsegment+=paux->nsegment;
				ts->data=(char *) realloc(ts->data,ts->datasize+paux->datasize);
				count=0;
				for(i=0;i<paux->nsegment;i++){
					for(j=0;j<paux->segments[i];j++)
						ts->data[ts->datasize+count+j]=paux->data[count+j];
					count+=paux->segments[i];
				}
				ts->datasize+=paux->datasize;
				ts->next=paux->next;
				free(paux->data);
				free(paux->segments);
				free(paux);
			}
			if(ts->granule!=0){
				bq=(bloque*)malloc(sizeof(bloque));
				bq->timecode=ts->granule/granulerate *100;
				bq->frames=0;
				for(i=0;i<ts->nsegment;i++){
					if(ts->segments[i]<255)
						bq->frames++;
				}

				count=0;
				j=0;
				for(i=0; i<bq->frames-1;i++){
					do{
						count+=ts->segments[j];
						j++;
					}while(ts->segments[j]<255&&j<ts->nsegment);
				}
				bq->size = count/255 + 1;
				bq->data=ts->data;
				
				if(TB.inicio!=NULL)
					TB.fin->next=bq;
				else
					TB.inicio=bq;
				TB.fin=bq;
			}
			else{
				//Codigosprivados
			}
				
		}
		else
			free(ts->data);
		free(ts->segments);				
		paux=ts;
		ts=ts->next;
		free(paux);
		
	}while(ts!=T.fin);
/*
	FILE *nuevo;
	nuevo=fopen("output.mkv","w");

	putc(0x1A,nuevo);putc(0x41,nuevo);putc(0xFE,nuevo);//EBML
	putc(0x93,nuevo);
	putc(0x42,nuevo);putc(0x86,nuevo);//EBMLVersion
	putc(0x81,nuevo);
	putc(1,nuevo);
	putc(0x42,nuevo);putc(0xF7,nuevo);//EBMLReadVersion
	putc(0x81,nuevo);
	putc(1,nuevo);
	putc(0x42,nuevo);putc(0xF2,nuevo);//EBMLMaxIDLength
	putc(0x81,nuevo);
	putc(4,nuevo);
	putc(0x42,nuevo);putc(0xF3,nuevo);//EBMLMaxSizeLength
	putc(0x81,nuevo);
	putc(8,nuevo);
	putc(0x42,nuevo);putc(0x82,nuevo);//Doctype
	putc(0x88,nuevo);
	fputs("matroska",nuevo);
	putc(0x42,nuevo);putc(0x87,nuevo);//DocTypeVersion
	putc(0x81,nuevo);
	putc(3,nuevo);
	putc(0x42,nuevo);putc(0x87,nuevo);//DocTypeReadVersion
	putc(0x81,nuevo);
	putc(3,nuevo);

	putc(0x18,nuevo);putc(0x53,nuevo);putc(0x80,nuevo);putc(0x67,nuevo);//Segment
//	putc(0x93,nuevo); tamaño por  definir.
	putc(0x15,nuevo);putc(0x49,nuevo);putc(0xA9,nuevo);putc(0x66,nuevo);//SegmentInfo
//Tamaño
	putc(0x2A,nuevo);putc(0xD7,nuevo);putc(0xB1,nuevo);//TimecodeScale
//PPOR DEFINIR TAMAÑO Y VALOR
	putc(0x4A,nuevo);putc(0x80,nuevo);//MuxingApp
//DESPUES LO DEFINO
	putc(0x57,nuevo);putc(0x41,nuevo);//WritingApp
//DESPUES LO DEFINO
	putc(0x16,nuevo);putc(0x54,nuevo);putc(0xAE,nuevo);putc(0x6B,nuevo);//tracks
		
*/
}

int main (){

	yyin = stdin;
	ts=NULL;
	T.inicio=NULL;
	T.fin=NULL;
	TB.inicio=NULL;
	TB.fin=NULL;
	yyparse();
	MKV();
	printf("Fin del Analisis\n");
}
